package com.briup.smartlabs.web.controller;

import java.util.List;
import java.util.Map;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import com.briup.smartlabs.bean.SmartLabs;
import com.briup.smartlabs.common.utils.Response;
import com.briup.smartlabs.service.LabsService;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags = "实验室信息服务")
@RestController
@RequestMapping("/labs")
@RequiredArgsConstructor
public class LabsController {

    private final LabsService labsService;

    @GetMapping("/by/condition")
    @ApiOperation("按条件分页查询实验室")
    public Response<PageInfo<SmartLabs>> findByCondition(@RequestParam(required = false) Integer pageNum,
                                                         @RequestParam(required = false) Integer pageSize,
                                                         @RequestParam(required = false) String name) {
        PageInfo<SmartLabs> byCondition = labsService.findByCondition(pageNum, pageSize, name);
        return Response.ok(byCondition);
    }


    @DeleteMapping("/batch")
    @ApiOperation("批量删除")
    public Response<Map<String, List<String>>> removeLabsByIds(@RequestParam List<String> ids) {
        Map<String, List<String>> map = labsService.removeByBatch(ids);
        return Response.ok(map);
    }


    @DeleteMapping("/undefined")
    public Response removeById(String id){
        labsService.removeById(id);
        return Response.ok("删除成功");
    }

    @PostMapping("/lab")
    @ApiOperation("新增和编辑实验室")
    public Response<String> saveOrUpdate(@RequestBody SmartLabs smartLabs) {
        labsService.saveOrUpdate(smartLabs);
        return Response.ok("操作成功");
    }
}









